package work.mediway.mdm.biz.job;

import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;

import org.springframework.stereotype.Component;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.TimeInterval;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import work.mediway.mdm.biz.service.biz.DictStatisticsJobService;

/**
 * @author zhongyj <1126834403@qq.com><br/>
 * @date 2020/8/5
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class DictStatisticsJob {

    private final DictStatisticsJobService dictStatisticsJobService;

    /**
     * 统计字典的增量信息
     * Scheduled(cron = "0 0 0 * * ? ")
     * 每天晚上12点运行
     */
    @XxlJob("dictChangeHandler")
    public ReturnT<String> dictChangeHandler() {
        ReturnT<String> returnT = new ReturnT<>();
        TimeInterval timer = DateUtil.timer();
        log.info("========================== 定时任务统计字典的增量信息 开始 ==========================");
        this.dictStatisticsJobService.statisticsChange(DateUtil.today());
        log.info("========================== 定时任务统计字典的增量信息 完成, 用时: {} ==========================", timer.intervalPretty());
        return returnT;
    }

    /**
     * 统计表信息存入CT_CodeSystem
     */
    @XxlJob("dictTableHandler")
    public ReturnT<String> dictTableHandler(String schema) {
        ReturnT<String> returnT = new ReturnT<>();
        TimeInterval timer = DateUtil.timer();
        log.info("========================== 定时任务统计字典表信息 开始 ==========================");
        this.dictStatisticsJobService.statisticsDictTable(schema);
        log.info("========================== 定时任务统计字典表信息 完成 ==========================, 用时: {} ==========================", timer.intervalPretty());
        return returnT;
    }

}









